package org.linlinjava.litemall.db.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallCustomerMapper;
import org.linlinjava.litemall.db.domain.LitemallCustomer;
import org.linlinjava.litemall.db.domain.LitemallSeckill;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class CustomerService {

    @Resource
    private LitemallCustomerMapper customerMapper;

    public List<LitemallCustomer> querySelective(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        QueryWrapper<LitemallCustomer> objectQueryWrapper = new QueryWrapper<>();
        return customerMapper.selectList(objectQueryWrapper);
    }

    public int updateById(LitemallCustomer customer) {
        customer.setUpdateTime(LocalDateTime.now());
        return customerMapper.updateById(customer);
    }

    public void deleteById(Integer id) {
        customerMapper.deleteById(id);
    }

    public void add(LitemallCustomer customer) {
        customer.setAddTime(LocalDateTime.now());
        customer.setUpdateTime(LocalDateTime.now());
        customerMapper.insertCustomer(customer);
    }

    public LitemallCustomer findById(Integer id) {
        return customerMapper.selectById(id);
    }

    public List<LitemallCustomer> customerInfo() {
        return customerMapper.selectList(Wrappers.<LitemallCustomer>lambdaQuery().eq(LitemallCustomer::getDeleted, false));
    }
}
